import TextWidget from './text-widget.js'
import MathParser from "../math-parser.js"
import {WIDGET_TYPE} from './widget-const.js';

export default class MathWidget extends TextWidget {
    constructor(sectionData, dispatcher) {
        super(sectionData, dispatcher);
    }
    get sectionData() {
        this._sectionData.type = WIDGET_TYPE.MATH;
        return this._sectionData;
    }
    get language() {return 'mathematica';}
    Init() {
        super.Init();
        this._editContainerElem.setAttribute('data-language', 'math');
        return this;
    }
    _UpdateView() {
        try {
            MathParser.MathStringToHTML(this.textareaText).then((_HTMLContent) => {
                this._viewContainerElem.innerHTML = _HTMLContent;
            });
        } catch (e) {
            this._viewContainerElem.innerText = e.message;
            console.log(e.stack);
        }
    }
};

